package ming;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.UnsupportedEncodingException;

public class LoginServlet extends HttpServlet {

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        request.getRequestDispatcher("/login.jsp").forward(request,response);

    }
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=utf-8");

        String name = request.getParameter("name");
        String pw = request.getParameter("password");

        if(pw.equals("123"))
        {
            System.out.println("登录成功");
            request.setAttribute("result", "登录成功，欢迎"+name);
        }
        else
        {
            System.out.println("登录失败");
            request.setAttribute("result", "登录失败，密码"+pw);
        }
        request.getRequestDispatcher("/login.jsp").forward(request,response);
    }
}
